package org.example.diary.exceptions;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;

import java.util.Collection;

public class BizAssertUtil {


    public static void isTrue(boolean expression, SystemErrorCode errorCode) {
        isTrue(expression, errorCode, errorCode.getMessage());
    }

    public static void isTrue(boolean expression, SystemErrorCode errorCode, String message) {
        if (expression) {
            SystemException.throwing(errorCode, message);
        }
    }

    public static void isNull(Object object, SystemErrorCode errorCode) {
        isNull(object, errorCode, errorCode.getMessage());
    }

    public static void isNull(Object object, SystemErrorCode errorCode, String message) {
        if (object instanceof Collection) {
            isTrue(CollectionUtils.isEmpty((Collection) object), errorCode, message);
        } else {
            isTrue(object == null, errorCode, message);
        }
    }
}
